import { director, Scheduler } from "cc";

export class PowerRecoveryMgr  {
    private timerCallMap: Map<Function, Function> = new Map();
    private static _instance: PowerRecoveryMgr;
    public static get instance(): PowerRecoveryMgr {
        if (!this._instance) {
            this._instance = new PowerRecoveryMgr();
        }
        return this._instance;
    }
    
    init() {
        Scheduler.enableForTarget(this); // 新增此行注册目标ID
        director.getScheduler().schedule(this.update,this,1);
    }

    start() {
        return this;
    }
    call(callback: Function) {
        if(this.timerCallMap.has(callback)){ return this;  }
        this.timerCallMap.set(callback, callback)
        return this;
    }
    update(dt: number) {
        //一秒后执行
        this.timerCallMap.forEach((callback) => {
           
            callback&&callback(dt) 
        })
    }

}